
<%@ include file="/html/portlet/ext/myprofile/init.jsp" %>

<%
	SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
	User selUser = UserLocalServiceUtil.getUserById(userId);
	long p_u_i_d = (selUser != null) ? selUser.getUserId() : 0 ;
	long portrait_id = (selUser != null) ? selUser.getPortraitId(): 0; 
	String profileId = request.getParameter("profileId");
	
	MyProfile myprofile = MyProfileUtil.fetchByUserId(userId);	
	Contact ct = ContactLocalServiceUtil.getContact(selUser.getContactId());
		
	Date dob = ct.getBirthday();
	Date now = new Date();	
	long diff = now.getTime() - dob.getTime();
	int months = (int) (diff / (1000*60*60*24));		
	int years = (int)(months / 365.25);
	int mnths = months -(years*12);		
	String age = years + " Years";
	
	long addresId = 0L;
	
	List adder = AddressUtil.findAll();				
		for(int i=0;i<adder.size();i++){
			Address addss = (Address)adder.get(i);
			  if(addss.getClassPK()==ct.getContactId()){
				addresId = addss.getAddressId();
		}
	}

	Address addr = AddressLocalServiceUtil.getAddress(addresId);	

	long phId =0L;
	List pho = PhoneUtil.findAll();				
		for(int i=0;i<pho.size();i++){
			Phone ph = (Phone)pho.get(i);
			  if(ph.getClassPK()==ct.getContactId()){
				phId = ph.getPhoneId();
				
			  }
		}	
	
	Phone phon = PhoneLocalServiceUtil.getPhone(phId);	
	
	int prefixId = BeanParamUtil.getInteger(ct, request, "prefixId");
	List<ListType> prefixes = ListTypeServiceUtil.getListTypes(ListTypeImpl.CONTACT_PREFIX);
	String relationWith = "";
	String prName="";
	for (ListType prefix : prefixes) {
		if(prefix.getListTypeId() == prefixId) {
		 prName = prefix.getName();
		}
	}
	
	PortletURL url1 = renderResponse.createActionURL();
	url1.setWindowState(WindowState.NORMAL);
	url1.setParameter("struts_action", "/ext/myprofile/add_profile");
	url1.setParameter("cmd", "EDIT");
%>


<script type="text/javascript">
	function submit(url) {
		var frm = document.<portlet:namespace/>fm;
		submitForm(frm,url);
	}
</script>


<script type="text/javascript">
jQuery(document).ready(function(){
	
	jQuery(".accordion h3:first").addClass("active");
	jQuery(".accordion p:not(:first)").hide();

	jQuery(".accordion h3").click(function(){
		jQuery(this).next("p").slideToggle("slow");
		
		jQuery(this).toggleClass("active");
		jQuery(this).siblings("h3").removeClass("active");
	});

});
</script>
<style type="text/css">
body {
	
	font: 75%/120% Arial, Helvetica, sans-serif;
}
.accordion {
	
	border-bottom: solid 1px #c4c4c4;
}
.accordion h3 {
	background: #e9e7e7 url(/html/portlet/ext/myprofile/images/arrow-square.gif) no-repeat right -51px;
	padding: 7px 15px;	
	font: bold 120%/100% Arial, Helvetica, sans-serif;
	border: solid 1px #c4c4c4;
	border-bottom: none;
	cursor: pointer;
	color:Brown
}
.accordion h3:hover {
	background-color: #e3e2e2;
}
.accordion h3.active {
	background-position: right 5px;
}
.accordion p {
	background: #f7f7f7;
	margin: 0;
	padding: 10px 15px 20px;
	border-left: solid 1px #c4c4c4;
	border-right: solid 1px #c4c4c4;
	align: right;	
}

</style>
<fieldset class="block-labels col">
	<div>
		My Photo: 
		<img alt="<%= selUser.getFullName() %>" class="avatar" src="<%= themeDisplay.getPathImage() %>/user_<%= selUser.isFemale() ? "female" : "male" %>_portrait?img_id=<%= selUser.getPortraitId() %>&t=<%= ImageServletTokenUtil.getToken(selUser.getPortraitId()) %>" />
		<%if (group.isCommunity() || (!group.isCommunity() && (theme1.getUserId()==grUserId)) ) {%>
			<% url1.setParameter("profileId", String.valueOf(myprofile.getProfileId())); %>
			<a href="javascript:void 0" onClick="submit('<%=url1.toString()%>');">Edit &raquo;</a>
		<%}%>	
	</div>	
</fieldset>
<form name="<portlet:namespace/>fm"  method="POST">
		<div class="accordion">
		<%
		if(selUser.getComments().equals("school")){	
		School sc = SchoolUtil.fetchByMyProfileUserId(userId);			
		%>
		<h3>School Details </h3>
		<p>Name of the School:<%=sc.getName()%> <br/><br/> 
		   Date of Establishment: <%=sdf.format(sc.getDateOfEstablishment())%> <br/><br/> 
		   Board of the School: <%=sc.getBoard().equals("Others") ? sc.getOthers():sc.getBoard()%> <br/><br/>
		   Website :<%=sc.getWebsite()%><br/><br/>
		   Number of Students :<%=sc.getNoOfStudents()%><br/><br/>
 		   Number of Teachers :<%=sc.getNoOfTeachers()%><br/><br/>			
		</p>
	       <%}%>
		<%
		if(selUser.getComments().equals("college")){	
		College cg = CollegeUtil.fetchByMyProfileUserId(userId);	
		
		%>
		<h3>College Details </h3>
		<p>Name of the College:<%=cg.getName()%> <br/><br/> 
		   Date of Establishment: <%=sdf.format(cg.getDateOfEstablishment())%> <br/><br/> 
		   Name of the University: <%=cg.getUniversity()%> <br/><br/>
		   Website :<%=cg.getWebsite()%><br/><br/>
		   Number of Students :<%=cg.getNoOfStudents()%><br/><br/>
 		   Number of Staffs :<%=cg.getNoOfStaffs()%><br/><br/>			
		</p>
	       <%}%>		



		<h3>Name Details </h3>
		<p> Name :
		   <%if(!selUser.getComments().equals("student")){%>
		   <%=prName%>
		   <%}%>
		   <%=ct.getFirstName()%> 
		   <%=ct.getLastName()%> <br/><br/>
		   Gender    :<%=ct.getMale()?"Male":"Female"%> <br/><br/>
		   Email Address: <%=selUser.getEmailAddress()%> <br/><br/>
		  <%if(selUser.getComments().equals("student")){%>
			Standard:
			<%}
			else if(selUser.getComments().equals("collStudent")){%>
			Degree:
			<%}else if(selUser.getComments().equals("")){%>			
			<%}else {%>
			Job Title:
			<%}%>
		<%if(!(selUser.getComments().equals(""))){
		CollStudent ctt = CollStudentUtil.fetchByMyProfileUserId(userId);
		%>
		 <%=(ct.getJobTitle().equals("")||ct.getJobTitle().equals("Others"))?ctt.getOthers():ct.getJobTitle()%> <br/><br/>
		 <%}%>
		   Age: <%=age%><br/><br/>		   
		     
		<%if(selUser.getComments().equals("student")){	
		Student st = StudentUtil.fetchByMyProfileUserId(userId);	
		School school = SchoolLocalServiceUtil.getSchool(st.getSchoolId());
		Parent pr = ParentUtil.fetchByParentDetail(st.getRollNo(),st.getSchoolId());
		%>
		
		Name of the School:<%=school.getName()%> <br/><br/> 		
		Board of the School: <%=school.getBoard().equals("Others") ? school.getOthers():school.getBoard()%> <br/><br/>
		Website :<%=school.getWebsite()%><br/><br/>
		<%if(pr!=null){
		   	Integer relation = (Integer) pr.getRelation();
		   	if(relation == 1 ) {
		   		relationWith = "Mother Name";
		   	} else	if(relation == 2 ) {
		   		relationWith = "Father Name";
		   	} else	if(relation == 3 ) {
		   		relationWith = "Guardian Name";
		   	}%>
		<%=relationWith%>:<%=pr.getFirstName()%><br/><br/>		
		<%}		
		}%>
		
		<%if(selUser.getComments().equals("collStudent")){	
		CollStudent ctt = CollStudentUtil.fetchByMyProfileUserId(userId);	
		College coll = CollegeLocalServiceUtil.getCollege(ctt.getCollegeId());		
		%>		
		Name of the College:<%=coll.getName()%> <br/><br/> 		
		Name of the University: <%=coll.getUniversity()%> <br/><br/>
		Website :<%=coll.getWebsite()%><br/><br/>
		<%}%>
		
		
		<%if(selUser.getComments().equals("teacher")){	
		Teacher tr = TeacherUtil.fetchByMyProfileUserId(userId);	
		School sctr = SchoolLocalServiceUtil.getSchool(tr.getSchoolId());		
		%>
		
		Name of the School:<%=sctr.getName()%> <br/><br/> 		
		Board of the School: <%=sctr.getBoard().equals("Others") ? sctr.getOthers():sctr.getBoard()%><br/><br/>
		Website :<%=sctr.getWebsite()%><br/><br/>			
		<%}%>
		
		<%if(selUser.getComments().equals("staff")){	
		Staff sf = StaffUtil.fetchByMyProfileUserId(userId);	
		College colle = CollegeLocalServiceUtil.getCollege(sf.getCollegeId());			
		%>
		
		Name of the College:<%=colle.getName()%> <br/><br/> 		
		Board of the University: <%=colle.getUniversity()%><br/><br/>
		Website :<%=colle.getWebsite()%><br/><br/>			
		<%}%>
		
		   <%Country country = CountryServiceUtil.getCountry(addr.getCountryId());%>
		   Country  : <%=country.getName()%><br/><br/>
		   <%Region region = RegionServiceUtil.getRegion(addr.getRegionId());%>
		   Region  : <%=region.getName()%><br/><br/>

		   City  : <%=addr.getCity()%>	<br/><br/>		
		   Street:<%=addr.getStreet1()%> <br/><br/>
		   Zip   :<%=addr.getZip()%>    <br/><br/>
					
			
		<%if (group.isCommunity() || (!group.isCommunity() && (theme1.getUserId()==grUserId)) ) {%>
			<% url1.setParameter("profileId", String.valueOf(myprofile.getProfileId())); %>
			<a href="javascript:void 0" onClick="submit('<%=url1.toString()%>');">Edit &raquo;</a>
		<%}%>
		
		</p>
		<%if(myprofile!=null){%>
		<h3>Personal Details </h3>
		<p><%if(!(selUser.getComments().equals("school")|| selUser.getComments().equals("college"))){%>
		   Family:<%=myprofile.getFamily()%> <br/><br/> 		   
		   AboutMe: <%=myprofile.getAboutMe()%> <br/><br/> 
	 	   <%}%>
		   
		   Phone: <%=phon.getNumber()%> <br/><br/> 		  
	       
		<%if (group.isCommunity() || (!group.isCommunity() && (theme1.getUserId()==grUserId)) ) {%>
		<% url1.setParameter("profileId", String.valueOf(myprofile.getProfileId())); %>
		<a href="javascript:void 0" onClick="submit('<%=url1.toString()%>');">Edit &raquo;</a>
		<%}%>
		</p>
		<%}%>
		<%if(myprofile!=null && !(selUser.getComments().equals("student") || selUser.getComments().equals("collStudent")) ){%>
			<h3>Education </h3>			
			<p> 
			<%if(!(selUser.getComments().equals("teacher")||(selUser.getComments().equals("staff")))){%>			
			Education:<%=myprofile.getEducation()%> <br/><br/>
			<%}%>
			<%if(selUser.getComments().equals("staff")){
			Staff sf = StaffUtil.fetchByMyProfileUserId(userId);
			%>
			Qualification:<%=sf.getQualification()%><br/><br/>
			<%}%>
			<%if(selUser.getComments().equals("teacher")){
			Teacher tr = TeacherUtil.fetchByMyProfileUserId(userId);
			%>
			Qualification:<%=tr.getQualification()%><br/><br/>
			<%}%>
		 	Employment:<%=myprofile.getEmployment()%><br/><br/>
		 	Experience:<%=myprofile.getExperience()%><br/><br/>
			<%if(!(selUser.getComments().equals("school")||(selUser.getComments().equals("college")))){%>		 	
		 	Goals:<%=myprofile.getGoals()%><br/><br/> 
			<%}%>
		<%if (group.isCommunity() || (!group.isCommunity() && (theme1.getUserId()==grUserId)) ) {%>
		<% url1.setParameter("profileId", String.valueOf(myprofile.getProfileId())); %>
		<a href="javascript:void 0" onClick="submit('<%=url1.toString()%>');">Edit &raquo;</a>
		<%}%>
		</p>
		<%}%>

		<%if(myprofile!=null && !(selUser.getComments().equals("school")|| selUser.getComments().equals("college"))){%>
		<h3>General Details </h3>
		<p>MyFavoirate:<%=myprofile.getMyFavoirate()%><br/><br/>		
		Strength:<%=myprofile.getStrength()%><br/><br/>
		Weakness:<%=myprofile.getWeakness()%><br/><br/>
		Interests:<%=myprofile.getInterests()%><br/><br/>
		Hobbies:<%=myprofile.getHobbies()%><br/><br/>
		Languages:<%=myprofile.getLanguages()%><br/><br/>
		<%if (group.isCommunity() || (!group.isCommunity() && (theme1.getUserId()==grUserId)) ) {%>
		<% url1.setParameter("profileId", String.valueOf(myprofile.getProfileId())); %>
		<a href="javascript:void 0" onClick="submit('<%=url1.toString()%>');">Edit &raquo;</a>
		<%}%>		
		</p>
		<%}%>		
		
		<%if(myprofile!=null && (selUser.getComments().equals("school")|| 
			selUser.getComments().equals("teacher") || 
			selUser.getComments().equals("parent") ||
			selUser.getComments().equals("staff") || 
			selUser.getComments().equals("collStudent") || 
			selUser.getComments().equals("student")) ){%>
						
		
<div>
	<%	
	List genList = new ArrayList();	
	if (group.isCommunity() || (!group.isCommunity() && (theme1.getUserId()==grUserId)) ) {%>
	<h3>Others Details </h3>
	<% 
		if(selUser.getComments().equals("parent")){	
		Parent pr = ParentUtil.fetchByMyProfileUserId(userId);	
		Student stdr = StudentUtil.fetchBySchoolIdRollNo(pr.getSchoolId(),pr.getRollNo());		
	%>
	
		Name of the <%=stdr.getGender()?"Son":"daughter"%>:<%genList.add(stdr);
		}
		
		if(selUser.getComments().equals("school")){
			out.println("Teachers:");
			genList = new ArrayList();
			School scc = SchoolUtil.fetchByMyProfileUserId(userId);					
			genList = TeacherUtil.findBySchoolId(scc.getSchoolId());			
		}
		if(selUser.getComments().equals("teacher")){
			out.println("School:");
			genList = new ArrayList();
			Teacher tc = TeacherUtil.fetchByMyProfileUserId(userId);								
			genList.add(SchoolUtil.findByPrimaryKey(tc.getSchoolId()));			
		}
		if(selUser.getComments().equals("staff")){
			out.println("College:");
			genList = new ArrayList();
			Staff sf = StaffUtil.fetchByMyProfileUserId(userId);							
			genList.add(CollegeUtil.findByPrimaryKey(sf.getCollegeId()));			
		}
		if(selUser.getComments().equals("student")){
			out.println("School:");
			genList = new ArrayList();
			Student stt = StudentUtil.fetchByMyProfileUserId(userId);								
			genList.add(SchoolUtil.findByPrimaryKey(stt.getSchoolId()));			
		}
		if(selUser.getComments().equals("collStudent")){
			out.println("College:");
			genList = new ArrayList();
			CollStudent cs = CollStudentUtil.fetchByMyProfileUserId(userId);								
			genList.add(CollegeUtil.findByPrimaryKey(cs.getCollegeId()));			
		}

	}
	%>
	
	<%
	long d = 0L;
	String ss = "";
	for(int v=0; v < genList.size(); v++){
		if(selUser.getComments().equals("parent")){	
		Student stu = (Student) genList.get(v);
		 d = stu.getUserId();
		 ss = stu.getFirstName();		
		}
		if(selUser.getComments().equals("school")){		
		Teacher trr = (Teacher) genList.get(v);
		 d = trr.getUserId();
		 ss = trr.getFirstName();
		}
		if(selUser.getComments().equals("teacher")||selUser.getComments().equals("student")){		
		School sch = (School) genList.get(v);
		 d = sch.getUserId();
		 ss = sch.getName();
		out.println(ss+"  School");
		}
		if(selUser.getComments().equals("staff")||selUser.getComments().equals("collStudent")){		
		College ch = (College) genList.get(v);
		 d = ch.getUserId();
		 ss = ch.getName();
		out.println(ss+"  College");
		}		
	%>	
	<liferay-ui:user-display userId="<%= d %>" userName="<%= ss %>" displayStyle="1"/> 
	<%
	}
	%>
		
</div>
<%}%>
</div>		
</form>